# encoding = utf-8

from application.logging import logger

from application.model.v3_model.CV_Parameter_online.get_best_params_ import get_best_params_
from application.utils.CodeTimingUtil import CodeTimingUtil


@CodeTimingUtil(name="[调参]CV_learn")
def CV_learn(
        train_x, train_y,
        n_estimators, max_depth,
        min_child_weight, gamma,
        subsample, colsample_bytree,
        reg_alpha, reg_lambda
):
    #
    cv_params = {
        'learning_rate': [0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.1, 0.2]
    }
    #
    other_params = {
        'learning_rate': 0.05,
        'n_estimators': n_estimators,
        'max_depth': max_depth,
        'min_child_weight': min_child_weight,
        'seed': 0,
        'subsample': subsample,
        'colsample_bytree': colsample_bytree,
        'gamma': gamma,
        'reg_alpha': reg_alpha,
        'reg_lambda': reg_lambda
    }
    #
    logger.info(f"调参开始[learning_rate]: {'*' * 50}")
    best_params_ = get_best_params_(train_x=train_x, train_y=train_y, cv_params=cv_params, other_params=other_params)
    learning_rate = best_params_["learning_rate"]
    logger.info(f"调参结束[learning_rate]:[{learning_rate}] {'*' * 50}")
    return learning_rate

    pass


pass

if __name__ == '__main__':
    pass
